from xml2dict import *

dict_info = {"keyboard": 
                {"page": 
                    {"key":{
                            "FA0101": {"imgfile": "./test/res/left.png", "key_char": "a", "shell": "./test/func.sh"},
                            "FA0102": {"imgfile": "./test/res/null.png", "key_mode": "Shift", "key_sticky": True},
                            "FA0103": {"imgfile": "./test/res/right.png", "key_char": "q", "key_mode": "Control", "plc_addr": 1020.1}
                        },
                    "svgFile": "./default.svg",
                    "mpIndex": 0, "id": "ATE_MP1",
                    "imgFile": "./test/res/default.png"},
                "id": "ATE_RANDOM",
                "h": 83,
                "x": 10,
                "y": 50,
                "w": 188}
            }

xml_text = """
<data>
    <country name="Liechtenstein">
        <rank>1</rank>
        <year>2008</year>
        <gdppc>141100</gdppc>
        <neighbor name="Austria" direction="E"/>
        <neighbor name="Switzerland" direction="W"/>
    </country>
    <country name="Singapore">
        <rank>4</rank>
        <year>2011</year>
        <gdppc>59900</gdppc>
        <neighbor name="Malaysia" direction="N"/>
    </country>
    <country name="Panama">
        <rank>68</rank>
        <year>2011</year>
        <gdppc>13600</gdppc>
        <neighbor name="Costa Rica" direction="W"/>
        <neighbor name="Colombia" direction="E"/>
    </country>
</data>
"""


if __name__ == "__main__":
    xml = XmlNode()
    xml.load_from_xml(xml_text)
    print(xml.dump_to_dict())

    # str_json = xml.dump_to_json()
    # print(str_json)

    xml.save_to_file("./output.xml", "xml")
    # xml.pretty_xml_file("./output.xml")
